isTrue.js ➔ isTrue   D
last analyzed

Complexity

Conditions 28
Paths 25

Size

Total Lines 38

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 28
nc 25
nop 3
dl 0
loc 38
rs 4.648
c 0
b 0
f 0

How to fix   Complexity   

Complexity

Complex classes like isTrue.js ➔ isTrue often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
2
export default function isTrue(v1, operator, v2) {
3
  var eval1
4
  var eval2
5
  switch (operator) {
6
  case '!=':
7
    return (v1 != v2)
8
  case '!==':
9
    return (v1 !== v2)
10
  case '==':
11
    return (v1 == v2)
12
  case '===':
13
    return (v1 === v2)
14
  case '<':
15
    return (v1 < v2)
16
  case '<=':
17
    return (v1 <= v2)
18
  case '>':
19
    return (v1 > v2)
20
  case '>=':
21
    return (v1 >= v2)
22
  case '&&':
23
    eval1 = false
24
    eval2 = false
25
    if((!!v1 === true && !Array.isArray(v1))|| (Array.isArray(v1) && v1.length>0)) eval1 = true
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
26
    if((!!v2 === true && !Array.isArray(v2))|| (Array.isArray(v2) && v2.length>0)) eval2 = true
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
27
28
    return (eval1 && eval2)
29
  case '||':
30
    eval1 = false
31
    eval2 = false
32
    if((!!v1 === true && !Array.isArray(v1))|| (Array.isArray(v1) && v1.length>0)) eval1 = true
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
33
    if((!!v2 === true && !Array.isArray(v2))|| (Array.isArray(v2) && v2.length>0)) eval2 = true
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
34
35
    return (eval1 || eval2)
36
  default:
37
    return false
38
  }
39
}
40